<?php

class JobseekerController extends Controller{
    
    public function beforeAction($event) {
        $run = $_GET['r'];
        $lang = $_GET['lang'];
        if(!Yii::app()->session['client'] && (strtolower($run)=='jobseeker/list' || strtolower($run)=='jobseeker/detail'))
            $this->redirect("index.php?lang={$lang}&r=Client/FormLogin");
        return true;
    }

    public function actionList(){
        $lang = $_GET['lang'];
        $page = isset($_GET['p']) ? $_GET['p'] : 1;
        $dataPerpage = 5;
        if(isset($_GET['Keyword']) || isset($_GET['StaffID']) || isset($_GET['Province'])){
            $Keyword = $_GET['Keyword'];
            $StaffID = $_GET['StaffID'];
            $Province = $_GET['Province'];
            $jobseekerList = JobSeeker::getJobseekerListByKeyword($Keyword, $StaffID, $Province, $page, $dataPerpage, false);
        } else {
            $jobseekerList = JobSeeker::getJobseekerList($page, $dataPerpage, false);
        }
        $this->render('staffList', array(
            "lang" => $lang,
            'data' => $jobseekerList, 
            'page' => $page, 
            'dataPerpage' => $dataPerpage
        ));
    }
    
    public function actionDetail(){
        $lang = $_GET['lang'];
        if(isset($_GET['id'])){
            $staffDetail = JobSeeker::getDetailJobseeker($_GET['id']);
            $this->render('staffDetail', array(
            "lang" => $lang,
            'staffDetail' => $staffDetail
        ));
        } else {
            $this->redirect("index.php?lang={$lang}&r=Jobseeker/List");
        }
    }

    public function actionRegisterform(){
    $lang = $_GET['lang'];
    $jobID = isset($_GET['jobID'])?$_GET['jobID']:0;
    $jobDetail = JobsManage::GetInfoByID($jobID, $lang);
    $this->render('applicationform',array(
        "lang" => $lang,
        "jobID" => $jobID,
        "jobDetail" => $jobDetail
    ));
    }
    public function actionRegister(){
        if(isset($_POST)){
            $StaffName = $_POST['Name'];
            $Gender = $_POST['Gender'];
            $Nationality = $_POST['Nationality'];
            $DOB = $_POST['DOB'];
            $Address = $_POST['Address'];
            $ProvinceID = $_POST['Province'];
            $ZipCode = $_POST['ZipCode'];
            $Email = $_POST['Email'];
            $Phone = $_POST['Phone'];
            $Mobile = $_POST['Mobile'];
            $Education = $_POST['Education'];
            $Institution = $_POST['Institution'];
            $Major = $_POST['Major'];
            $EnSkill = $_POST['EnSkill'];
            $JpSkill = $_POST['JpSkill'];
            $WorkPosition = $_POST['WorkPosition'];
            $WorkExperienceDetail = $_POST['WorkExperienceDetail'];
            $ExpectWorkingPosition = $_POST['ExpectWorkingPosition'];
            $ExpectWorkingLocation = $_POST['ExpectWorkingLocation'];
            $ExpectSalary = $_POST['ExpectSalary'];
            $Note = $_POST['Note'];
            $JobID = $_POST['JobID'];
            $PageLanguage = $_POST['lang'];
            JobSeeker::insertJobseeker($StaffName, $Gender, $Nationality, $DOB, $Address, $ProvinceID, $ZipCode, $Email, $Phone, $Mobile, $Education, $Institution, $Major, $EnSkill, $JpSkill, $WorkPosition, $WorkExperienceDetail, $ExpectWorkingPosition, $ExpectWorkingLocation, $ExpectSalary, $Note, $JobID, $PageLanguage, 'U');
            $this->render('jobseekerThankyou',array(
                "lang" => $_POST['lang']
            ));
        }else{
            $this->actionRegisterform();
        }
    }
}
?>
